package com.ohc.leetcode.链表;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * 2022年6月22日19:22:56
 * https://leetcode.cn/problems/merge-k-sorted-lists/
 * 过
 */
public class 合并K个升序链表23 {
    private void digui(ListNode node) {
        List<ListNode> list = new ArrayList<>();

        if (node == null) {
            return;
        }
        System.out.println(node.val);
        digui(node.next);
    }

    public static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    private static ListNode createNode(List<Integer> list) {
        ListNode h = new ListNode(0);
        ListNode head = new ListNode(0);
        h.next = head;
        for (Integer num : list) {
            ListNode listNode = new ListNode(num);
            head.next = listNode;
            head = listNode;
        }
        return h.next.next;

    }

    public static ListNode mergeKLists(ListNode[] lists) {
        List<Integer> list = new ArrayList<>();
        for (ListNode listNode : lists) {
            while (listNode != null) {
                System.out.println(listNode.val);
                list.add(listNode.val);
            }
        }
        list.sort((o1, o2) -> o1 - o2);
        return createNode(list);

    }

    public static void main(String[] args) {

    }
}
